﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;

namespace Appology.SugarSync.IO.Primitives
{
    public abstract class SugarSyncPathInfo : INotifyPropertyChanged
    {
        protected SugarSyncPathInfo(SugarSyncAccount account, Uri refUri)
        {
            Account = account;
            RefUri = refUri;
        }

        private Uri _refUri;

        public Uri RefUri
        {
            get { return _refUri; }
            private set
            {
                if (_refUri != value)
                {
                    _refUri = value;
                    OnPropertyChanged("RefUri");
                }
            }
        }

        private Uri _parentRefUri;

        public Uri ParentRefUri
        {
            get { return _parentRefUri; }
            set
            {
                if (_parentRefUri != value)
                {
                    _parentRefUri = value;
                    OnPropertyChanged("ParentRefUri");
                }
            }
        }

        private string _name;

        public string Name
        {
            get { return _name; }
            protected set
            {
                if (_name != value)
                {
                    _name = value;
                    OnPropertyChanged("Name");
                }
            }
        }

        private DateTimeOffset _lastUpdated;

        public DateTimeOffset LastUpdated
        {
            get { return _lastUpdated; }
            set
            {
                if (_lastUpdated != value)
                {
                    _lastUpdated = value;
                    OnPropertyChanged("LastUpdated");
                }
            }
        }
        
        public abstract bool IsBusy { get; set; }
        
        public abstract Task RefreshAsync();
        
        private SugarSyncAccount _account;

        public SugarSyncAccount Account
        {
            get { return _account; }
            private set
            {
                if (_account != value)
                {
                    _account = value;
                    OnPropertyChanged("Account");
                }
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}